package com.btcode.common;

import java.util.HashMap;
import java.util.List;

/**
 * 命令行工具
 */
public class CLIUtil {

    /**
     * 检查命令行参数，格式如下 -launchtype windows
     * @param args
     * @return
     */
    public static HashMap<String,String> obantParam(String[] args, List<String> supportParams) throws Exception {

        HashMap<String,String> parms = new HashMap<>();

        if(args.length % 2 > 0){
            throw new Exception("参数个数有误");
        }

        for(int i=0;i<args.length;i+=2){
            String arg = args[i];
            if(!arg.startsWith("-")){
                throw new Exception("参数错误："+arg);
            }

            if(!supportParams.contains(arg.substring(1))){
                throw new Exception("参数不存在："+arg);
            }

            parms.put(arg.substring(1),args[i+1]);
        }

        return parms;
    }

}
